package com.oop.demo;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/14 11:55
 * @description
 */
public abstract class Animal {
    protected String name;
    protected int age;

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // 抽象方法：动物叫声‌:
    public abstract void makeSound();

    // 通用行为：进食‌
    public abstract void eat() ;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() { return name; }
    public int getAge() { return age; }
}
 class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }
    @Override
    public void makeSound() {
        System.out.println(name + " 狗叫");
    }

     @Override
     public void eat() {
         System.out.println(name+ " 狗啃骨头");
     }

     public void fetchBall() {
        System.out.println(name + " 狗玩球");
    }
}
class Cat extends Animal {
    public Cat(String name, int age) {
        super(name, age);
    }

    @Override
    public void makeSound() {
        System.out.println(name + " 猫叫");
    }

    @Override
    public void eat() {
        System.out.println(name+ " 猫吃鱼");
    }

    public void rubHuman() {
        System.out.println(name + "蹭人");
    }
}

